<html xmlns="http://www.w3.org/1999/xhtml"><head><style type="text/css">
dt {
  font-style: italic;
  margin-top: 15px;
  margin-bottom: 3px;
  margin-left: 0px;
  border-bottom: 1px dotted black;
}
dd {
  margin-left: 10px;
}
table {
  border-collapse:collapse;
  border: 1px solid black;
  margin-top: 7px;
}
th {
  border: 1px solid black;
  padding: 3 7 3 7;
}
td {
  border: 1px solid black;
  padding: 3 7 3 7;
}
</style></head><body><p><a name="getfield"></a><b>getfield</b> :
  get value of  object  field : <a href="opcodes.html">index</a> : <a href="http://asm.objectweb.org/asm40/javadoc/user/org/objectweb/asm/MethodVisitor.html#visitFieldInsn(int,%20java.lang.String,%20java.lang.String,%20java.lang.String)">visitFieldInsn()</a></p><dl><dt>Description</dt><dd>getfield pops <i xmlns="">objectref</i> (a reference to an object) from
the stack, retrieves the value of the field identified by &lt;field-spec&gt;
from <i xmlns="">objectref</i>, and pushes the one-word or two-word value onto the
operand stack. <br></br>For example, if you have the class:<br></br><pre>
    package xyz;
    class Point {
        public int xCoord, yCoord;
    };
</pre>
Then,
assuming p is an instance of the class Point, writing the Java expression:<br></br><pre>
    int x = p.xCoord;
</pre>
generates
a call to getfield like:<br></br><pre>
    aload_1                      ; push object in local varable 1 (i.e. p) onto the stack
    getfield xyz/Point/xCoord I  ; get the value of p.xCoord, which is an int
    istore_2                     ; store the int value in local variable 2 (x)
</pre>
In
Jasmin, getfield takes two parameters, &lt;field-spec&gt; and
&lt;descriptor&gt;. &lt;field-spec&gt; gives <i xmlns="">classname</i>, the name of the
class that defines the field, as well as <i xmlns="">fieldname</i>, as the name of the
field itself. In the example above, the &lt;field-spec&gt; is
"xyz/Point/xCoord", indicating that the <i xmlns="">classname</i> is "xyz/Point" and the
<i xmlns="">fieldname</i> is "xCoord". &lt;descriptor&gt; describes the type of data
held in the field, and is a standard Java type descriptor (see Chapter 4 for a
full description of type descriptors). In the example above, &lt;descriptor&gt;
is "I", since the field holds an integer.  <br></br>getfield first resolves <i xmlns="">classname</i> to a Java class. Then it
locates the <i xmlns="">fieldname</i> in that class, determining the <i xmlns="">width</i> of the
field (in bytes) and its <i xmlns="">offset</i> (in bytes) from the base of the object
data. The type of the field must match &lt;descriptor&gt;. See Chapter 7 for
more on how fields are resolved<br></br>To retrieve the value for the field, getfield obtains the bytes
starting at <i xmlns="">offset</i> and extending for <i xmlns="">width</i> bytes from the start
of <i xmlns="">objectref</i>'s instance data, expands it to either a 4-byte or 8-byte
value, and pushes the value onto the operand stack.</dd><dt>Exceptions</dt><dd>NullPointerException - <i xmlns="">objectref</i> is null</dd><dt>Notes</dt><dd>Fields cannot be overriden, although they can be 'shadowed'. For
example, with the two classes:<br></br><pre>
    class A { int x; }
and
    class B extends A { int x; }
</pre>
instances
of B will have storage for both the field "A/x" and the field "B/x". Which
field is accessed is determined by the class name given in
&lt;field-spec&gt;.</dd><dt>See also</dt><dd><a href="ref-putfield.html">putfield</a> <a href="ref-.html"></a> <a href="ref-putstatic.html">putstatic</a> <a href="ref-.html"></a> <a href="ref-getstatic.html">getstatic</a> </dd><dt>Stack</dt><dd><table xmlns="">
<tr>
<td>
<b>Before </b>
</td>
<td><b>After</b></td></tr>
<tr>
<td>objectref</td>
<td>value</td></tr>
<tr>
<td>...</td>
<td>...</td></tr>
</table></dd><dt>Bytecode</dt><dd><table xmlns="">
<tr>
<td>
<b> Type </b>
</td>
<td><b>Description</b></td></tr>
<tr>
<td>
u1 
</td>
<td>getfield
opcode = 0xB4 (180)
</td></tr>
<tr>
<td>
u2 
</td>
<td>index</td></tr>
</table></dd></dl></body></html>